package io.zw.modules.sys.controller;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.zw.common.utils.PageUtils;
import io.zw.common.utils.R;
import io.zw.common.validator.ValidatorUtils;
import io.zw.modules.sys.entity.DictEntity;
import io.zw.modules.sys.service.DictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("sys/dict")
public class DictController {
    @Autowired
    private DictService sysDictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:dict:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysDictService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/select")
    @RequiresPermissions("sys:dict:list")
    public R select(@RequestParam Map<String, String> params){
        String name=params.get("name");
        List<DictEntity> list=sysDictService.selectList(new EntityWrapper<DictEntity>().eq("del_flag",'0').like("name",params.get("name"), SqlLike.DEFAULT));
        return R.ok().put("list", name.equals("车辆类型")?list.stream().collect(Collectors.groupingBy(DictEntity::getName)):list);
    }

}
